package org.jawa.exam.model;

import java.util.Date;

import org.jawa.core.cache.CacheSizes;
import org.jawa.core.cache.Cacheable;
import org.jawa.core.cache.CannotCalculateSizeException;
import org.jawa.core.util.DateConvertUtils;

/**
 * 
 * 类文件: Exam
 * <p>
 * <p>
 * 类描述：考试信息
 * <p>
 * 作     者： migrant423
 * <p>
 * 日     期： 2012-7-16
 * <p>
 * 时     间： 下午9:52:29
 * <p>
 */
public class Exam implements Cacheable {

	private static final long serialVersionUID = -8217451576655332783L;

	protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	/**
	 * 考试编号
	 */
	private Long examId;
	/**
	 * 试卷编号
	 */
	private Long paperId;
	/**
	 * 考试名称
	 */
	private String examName;
	/**
	 * 考试须知
	 */
	private String examDesc;
	/**
	 * 考试开始时间
	 */
	private Date startTime;
	/**
	 * 考试结束时间
	 */
	private Date endTime;
	/**
	 * 考度失效时间
	 */
	private Long invalidTime;
	/**
	 * 考试模试
	 */
	private String examMode;
	/**允许参考次数
	 * 
	 */
	private Long joinNum;
	/**
	 * 计分方式
	 */
	private String scoreType;
	/**
	 * 折算分数
	 */
	private double convertScore;
	/**
	 * 及格分值
	 */
	private double passScore;
	/**
	 * 需要人工阅卷
	 */
	private String needManual;
	/**
	 * 公布考试结果
	 */
	private String publicResult;
	/**
	 * 公布时间
	 */
	private Date publicTime;
	/**
	 * 考试状态
	 */
	private String examStatus;
	/**
	 * 打乱试题顺序
	 */
	private String randomQuestion;
	/**
	 * 打乱题目选项顺序
	 */
	private String randomOption;
	/**
	 * 备注
	 */
	private String remark;
	
	public Long getExamId() {
		return examId;
	}

	public void setExamId(Long examId) {
		this.examId = examId;
	}

	public Long getPaperId() {
		return paperId;
	}

	public void setPaperId(Long paperId) {
		this.paperId = paperId;
	}

	public String getExamName() {
		return examName;
	}

	public void setExamName(String examName) {
		this.examName = examName;
	}

	public String getExamDesc() {
		return examDesc;
	}

	public void setExamDesc(String examDesc) {
		this.examDesc = examDesc;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	
	public String getStartTimeString() {
		return date2String(getStartTime(), DATE_TIME_FORMAT);
	}
	
	public void setStartTimeString(String value) {
		setStartTime(string2Date(value, DATE_TIME_FORMAT,java.util.Date.class));
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	
	public String getEndTimeString() {
		return date2String(getEndTime(), DATE_TIME_FORMAT);
	}
	public void setEndTimeString(String value) {
		setEndTime(string2Date(value, DATE_TIME_FORMAT,java.util.Date.class));
	}

	public Long getInvalidTime() {
		return invalidTime;
	}

	public void setInvalidTime(Long invalidTime) {
		this.invalidTime = invalidTime;
	}

	public String getExamMode() {
		return examMode;
	}

	public void setExamMode(String examMode) {
		this.examMode = examMode;
	}

	public Long getJoinNum() {
		return joinNum;
	}

	public void setJoinNum(Long joinNum) {
		this.joinNum = joinNum;
	}

	public String getScoreType() {
		return scoreType;
	}

	public void setScoreType(String scoreType) {
		this.scoreType = scoreType;
	}

	public double getConvertScore() {
		return convertScore;
	}

	public void setConvertScore(double convertScore) {
		this.convertScore = convertScore;
	}

	public double getPassScore() {
		return passScore;
	}

	public void setPassScore(double passScore) {
		this.passScore = passScore;
	}

	public String getNeedManual() {
		return needManual;
	}

	public void setNeedManual(String needManual) {
		this.needManual = needManual;
	}

	public String getPublicResult() {
		return publicResult;
	}

	public void setPublicResult(String publicResult) {
		this.publicResult = publicResult;
	}

	public Date getPublicTime() {
		return publicTime;
	}

	public void setPublicTime(Date publicTime) {
		this.publicTime = publicTime;
	}
	
	public String getPublicTimeString() {
		return date2String(getPublicTime(), DATE_TIME_FORMAT);
	}
	
	public void setPublicTimeString(String value) {
		setPublicTime(string2Date(value, DATE_TIME_FORMAT,java.util.Date.class));
	}

	public String getExamStatus() {
		return examStatus;
	}

	public void setExamStatus(String examStatus) {
		this.examStatus = examStatus;
	}

	public String getRandomQuestion() {
		return randomQuestion;
	}

	public void setRandomQuestion(String randomQuestion) {
		this.randomQuestion = randomQuestion;
	}

	public String getRandomOption() {
		return randomOption;
	}

	public void setRandomOption(String randomOption) {
		this.randomOption = randomOption;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * 用于将日期转为指定格式的字符串
	 * @param date 需要转换的日期(java.util.Date实例)
	 * @param dateFormat 指定的格式，如：yyyy-MM-dd HH:mm:ss
	 * @return 转换后的字符串
	 */
	public static String date2String(java.util.Date date, String dateFormat) {
		return DateConvertUtils.format(date, dateFormat);
	}

	/**
	 * 将字符串转换为日期
	 * @param dateString 必需是与yyyy-MM-dd HH:mm:ss相似的字符串
	 * @param dateFormat 日期格式
	 * @param targetResultType 返回的类型默认为：java.util.Date
	 * @return 返回格式后的日期实例
	 */
	public static <T extends java.util.Date> T string2Date(String dateString,
			String dateFormat, Class<T> targetResultType) {
		return DateConvertUtils.parse(dateString, dateFormat, targetResultType);
	}
	
	public int getCachedSize() throws CannotCalculateSizeException {
		int size = 0;
		size += CacheSizes.sizeOfObject();
		size += CacheSizes.sizeOfLong();
		size += CacheSizes.sizeOfLong();
		size+=CacheSizes.sizeOfString(examName);
		size+=CacheSizes.sizeOfString(examDesc);
		size += CacheSizes.sizeOfDate();
		size += CacheSizes.sizeOfDate();
		size += CacheSizes.sizeOfLong();
		size+=CacheSizes.sizeOfString(examMode);
		size += CacheSizes.sizeOfLong();
		size+=CacheSizes.sizeOfString(scoreType);
		size+=CacheSizes.sizeOfDouble();
		size+=CacheSizes.sizeOfDouble();
		
		size+=CacheSizes.sizeOfString(needManual);
		size+=CacheSizes.sizeOfString(publicResult);
		size += CacheSizes.sizeOfDate();
		size+=CacheSizes.sizeOfString(examStatus);
		size+=CacheSizes.sizeOfString(randomQuestion);
		size+=CacheSizes.sizeOfString(randomOption);
		size+=CacheSizes.sizeOfString(remark);
		return size;
	}

}
